package export.pet
{
	import base.*;
	
	import com.dusk.util.ResUtil;
	import com.game.data.vo.PetDataVO;
	
	import export.bullet.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class PetTiger4 extends BasePet
	{
		
		public function PetTiger4(param1:BaseHero, param2:PetDataVO)
		{
			super(param1, param2);
			this.horizonSpeed = 5;
			this.attackBackInfoDict["hit1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [6, -5],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackBackInfoDict["hit2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 7,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackBackInfoDict["hit3_1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [0, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "physics",
				"addEffect"      : [{
					"name"  : BaseAddEffect.PET_TIGER_SXHZ,
					"time"  : gc.frameClips * 2,
					"direct": 0
				}]
			};
			this.attackBackInfoDict["hit3_2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [0, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit4"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-8, 0],
				"attackInterval" : 3,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackRange = 40;
			this.setAction("idle");
			this.skillCD1 = [gc.frameClips * 4, gc.frameClips * 8];
			this.skillCD2 = [gc.frameClips * 5, gc.frameClips * 9];
			this.skillCD3 = [gc.frameClips * 6, gc.frameClips * 10];
			this.skillCD4 = [gc.frameClips * 30, gc.frameClips * 60];
		}
		
		private var aoyiStep:uint = 0;
		private var isAtkUp:Boolean = false;
		
		override protected function initBBDC():void
		{
			var _loc1_:Object = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("PetTigerBmd4");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 250, 250, new Point(0, 0));
				bbdc.setOffsetXY(15, -15);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 10], [2, 2, 2, 10], [2, 2, 10], [2, 2, 2, 2, 10], [3, 3, 3], [2, 2, 2, 50, 2, 2]]);
				bbdc.setFrameCount([6, 4, 1, 5, 4, 3, 5, 3, 6]);
				bbdc.setEnterFrameCallBack(this.enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("PetTigerBmd4--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(param1:String):void
		{
			super.setAction(param1);
			var _loc2_:Point = this.bbdc.getCurPoint();
			switch (param1)
			{
				case "idle":
					if (_loc2_.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(param1);
					break;
				case "walk":
					if (_loc2_.y != 1)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(1);
					}
					this.bbdc.setState(param1);
					break;
				case "hurt":
					this.aoyiStep = 0;
					if (_loc2_.y != 2)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(2);
					}
					this.bbdc.setState(param1);
					break;
				case "hit1":
					if (_loc2_.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(param1);
					break;
				case "hit2":
					if (_loc2_.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(param1);
					break;
				case "hit3":
					if (_loc2_.y != 5)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(5);
					}
					this.bbdc.setState(param1);
					break;
				case "hit4":
					if (_loc2_.y != 6)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(6);
					}
					this.bbdc.setState(param1);
					break;
				case "hit5":
					if (_loc2_.y != 7)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(7);
					}
					this.bbdc.setState(param1);
					break;
				case "hit6":
					this.isAtkUp = true;
					if (_loc2_.y != 8)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(8);
					}
					this.bbdc.setState(param1);
					break;
				case "dead":
					this.aoyiStep = 0;
					if (_loc2_.y != 3)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(3);
					}
					this.bbdc.setState(param1);
			}
		}
		
		override protected function scriptFrameOverFunc(param1:int):void
		{
			var _loc2_:String = this.bbdc.getState();
			switch (_loc2_)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
					break;
				case "idle":
					this.bbdc.setFramePointX(0);
					break;
				case "hit1":
					this.setAction("idle");
					if (this.aoyiStep == 1)
					{
						this.releSkill4WithoutMp();
					}
					if (this.aoyiStep == 2)
					{
						this.doBeforeHit5_3();
						break;
					}
					break;
				case "hit2":
					if (this.aoyiStep == 1)
					{
						this.releSkill4WithoutMp();
						break;
					}
					this.setAction("idle");
					break;
				case "hit3":
					if (this.aoyiStep == 2)
					{
						this.doBeforeHit5_3();
						break;
					}
					this.setAction("idle");
					break;
				case "hit4":
					if (this.aoyiStep > 0)
					{
						this.aoyiStep = 0;
					}
					this.setAction("idle");
					break;
				case "hit5":
					this.setAction("idle");
					break;
				case "hit6":
					this.doHit5_3();
					break;
				case "hurt":
					this.setStatic();
					this.setAction("idle");
					break;
				case "dead":
					this.destroy();
			}
		}
		
		override protected function enterFrameFunc(param1:Point):void
		{
			var _loc2_:String = this.bbdc.getState();
			var _loc3_:uint = this.getBBDC().getDirect();
			var _loc4_:Point = new Point();
			switch (_loc2_)
			{
				case "hit1":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 3)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 130;
								}
								else
								{
									_loc4_.x = this.x + 130;
								}
								_loc4_.y = this.y - 70;
								this.doHit1(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit2":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 3)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 190;
								}
								else
								{
									_loc4_.x = this.x + 190;
								}
								_loc4_.y = this.y - 80;
								this.doHit2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit3":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 50;
								}
								else
								{
									_loc4_.x = this.x + 50;
								}
								_loc4_.y = this.y - 65;
								this.doHit3_1(_loc3_, _loc4_);
								break;
							}
							if (this.bbdc.getCurFrameCount() == 1)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 200;
								}
								else
								{
									_loc4_.x = this.x + 200;
								}
								_loc4_.y = this.y - 200;
								this.doHit3_2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit4":
					if (param1.x == 0)
					{
						if (this.bbdc.getCurFrameCount() == 2)
						{
							if (_loc3_ == 0)
							{
								_loc4_.x = this.x - 85;
							}
							else
							{
								_loc4_.x = this.x + 85;
							}
							_loc4_.y = this.y - 130;
							this.doHit4_1(_loc3_, _loc4_);
						}
					}
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 4)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 105;
								}
								else
								{
									_loc4_.x = this.x + 105;
								}
								_loc4_.y = this.y - 2;
								this.doHit4_2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit5":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 1)
							{
								this.doHit5();
							}
						}
					}
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			var _loc1_:Number = Number(NaN);
			if (this.curAttackTarget)
			{
				_loc1_ = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
				return _loc1_ >= 50 && _loc1_ <= 100 && this.getMp() >= this._petInfo.findPetUsedMagic("hy") && Boolean(this._petInfo.findHasStudySkill("hy"));
			}
			return false;
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			var _loc1_:Number = Number(NaN);
			if (this.curAttackTarget)
			{
				_loc1_ = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
				return _loc1_ <= 80 && this.getMp() >= this._petInfo.findPetUsedMagic("sxhz") && Boolean(this._petInfo.findHasStudySkill("sxhz"));
			}
			return false;
		}
		
		override protected function beforeSkill3Start():Boolean
		{
			var _loc1_:Number = Number(NaN);
			if (this.curAttackTarget)
			{
				_loc1_ = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
				return _loc1_ <= 450 && this.getMp() >= this._petInfo.findPetUsedMagic("hsqj") && Boolean(this._petInfo.findHasStudySkill("hsqj"));
			}
			return false;
		}
		
		override protected function beforeSkill4Start():Boolean
		{
			return this.curAttackTarget != null && this.getMp() >= this._petInfo.findPetUsedMagic("bhaoyi") && Boolean(this._petInfo.findHasStudySkill("bhaoyi"));
		}
		
		override public function reduceHp(param1:int, param2:Boolean = false):void
		{
			super.reduceHp(param1, param2);
		}
		
		override protected function releSkill1():void
		{
			this.faceToTarget();
			
			this.setAction("hit2");
			this.lastHit = "hit2";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("hy"))
		}
		
		override protected function releSkill2():void
		{
			this.faceToTarget();
			
			this.setAction("hit3");
			this.lastHit = "hit3";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("sxhz"))
		}
		
		override protected function releSkill3():void
		{
			this.faceToTarget();
			
			this.setAction("hit4");
			this.lastHit = "hit4";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("hsqj"))
		}
		
		override protected function releSkill4():void
		{
			this.addAoyiBuff();
			this.faceToTarget();
			
			this.setAction("hit5");
			this.lastHit = "hit5";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("bhaoyi"));
		}
		
		override protected function normalHit():void
		{
			
			this.setAction("hit1");
			this.lastHit = "hit1";
			this.faceToTarget();
		}
		
		override public function getRealPower(param1:String, param2:Boolean = true):int
		{
			var _loc3_:Object = null;
			var _loc4_:uint = this.getCriteValue(param2) ? 2 : 1;
			var _loc5_:uint = this.getMagicAddValue();
			var _loc6_:Number = this.isGXP ? Number(1.2) : Number(1);
			switch (param1)
			{
				case "hit1":
					if (this.isAtkUp)
					{
						this.isAtkUp = false;
						return (this.getAtk() + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate()) * 1.3;
					}
					return (this.getAtk() + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					break;
				case "hit2":
					_loc3_ = this._petInfo.getPetHarmObj("hy");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit3_1":
					_loc3_ = this._petInfo.getPetHarmObj("sxhz");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit3_2":
					_loc3_ = this._petInfo.getPetHarmObj("sxhz");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit4":
					_loc3_ = this._petInfo.getPetHarmObj("hsqj");
					if (_loc3_)
					{
						if (this.isAtkUp)
						{
							this.isAtkUp = false;
							return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate()) * 1.3;
						}
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				default:
					return 0;
			}
		}
		
		override protected function exitFrameFunc(param1:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			if (!this.isBeAttacking())
			{
				super.myIntelligence();
			}
		}
		
		override public function isAttacking():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3" || this.curAction == "hit4" || this.curAction == "hit5" || this.curAction == "hit6";
		}
		
		override protected function isCannotMoveWhenAttackOnFloor():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3" || this.curAction == "hit4" || this.curAction == "hit5" || this.curAction == "hit6";
		}
		
		private function releSkill1WithoutMp():void
		{
			this.faceToTarget();
			
			this.setAction("hit2");
			this.lastHit = "hit2";
		}
		
		private function releSkill2WithoutMp():void
		{
			this.faceToTarget();
			
			this.setAction("hit3");
			this.lastHit = "hit3";
		}
		
		private function releSkill4WithoutMp():void
		{
			this.faceToTarget();
			
			this.setAction("hit5");
			this.lastHit = "hit5";
		}
		
		private function releSkill3WithoutMp():void
		{
			this.faceToTarget();
			
			this.setAction("hit4");
			this.lastHit = "hit4";
		}
		
		private function doHit1(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger2Bullet1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit1");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit2(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger1Bullet2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit2");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit3_1(param1:uint, param2:Point):void
		{
			this.attackBackInfoDict["hit3_1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [0, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic",
				"addEffect"      : [{
					"name"  : BaseAddEffect.PET_TIGER_SXHZ,
					"time"  : gc.frameClips * 2,
					"direct": param1
				}]
			};
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger2Bullet3_1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit3_1");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit3_2(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger2Bullet3_2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit3_2");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
			_loc3_.setFuncWhenHitTarget(this.doWhenHit3_2hit);
		}
		
		private function doWhenHit3_2hit(param1:BaseBullet):void
		{
			var _loc2_:Object = this._petInfo.getPetHarmObj("sxhz");
			if (_loc2_)
			{
				this.cureHp(_loc2_.first);
			}
		}
		
		private function doHit4_1(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger3Bullet4_1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setDisable();
			_loc3_.setAction("hit4");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit4_2(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetTiger3Bullet4_2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit4");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit5():void
		{
			trace("doHit5");
			this.setInvincible(gc.frameClips * 1);
			if (this.aoyiStep == 0)
			{
				this.aoyiStep = 1;
				if (this.curAttackTarget)
				{
					if (Math.random() < 0.5)
					{
						this.x = Number(this.curAttackTarget.x) - 80;
					}
					else
					{
						this.x = this.curAttackTarget.x + 80;
					}
					this.faceToTarget();
					if (this._petInfo.findHasStudySkill("hy"))
					{
						this.releSkill1WithoutMp();
					}
					else
					{
						this.normalHit();
					}
				}
			}
			else if (this.aoyiStep == 1)
			{
				if (this.curAttackTarget)
				{
					if (Math.random() < 0.5)
					{
						this.x = Number(this.curAttackTarget.x) - 80;
					}
					else
					{
						this.x = this.curAttackTarget.x + 80;
					}
					this.faceToTarget();
					this.doHit5_2();
				}
			}
		}
		
		private function doHit5_2():void
		{
			trace("doHit5_2");
			this.setInvincible(gc.frameClips * 1);
			this.aoyiStep = 2;
			if (this._petInfo.findHasStudySkill("sxhz"))
			{
				this.releSkill2WithoutMp();
			}
			else
			{
				this.normalHit();
			}
		}
		
		private function doBeforeHit5_3():void
		{
			this.setInvincible(gc.frameClips * 4);
			this.setAction("hit6");
			this.lastHit = "hit6";
		}
		
		private function doHit5_3():void
		{
			trace("doHit5_3");
			this.aoyiStep = 3;
			if (this._petInfo.findHasStudySkill("hsqj"))
			{
				this.releSkill3WithoutMp();
			}
			else
			{
				this.normalHit();
			}
		}
	}
}
